package com.xhwy.controller;

import com.xhwy.param.OrderDetailIdParam;
import com.xhwy.param.OrderParam;
import com.xhwy.param.UserIdParam;
import com.xhwy.service.OrderService;
import com.xhwy.util.PageUtil;
import com.xhwy.util.R;
import com.xhwy.vo.admin.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("myOrder")
    public R myOrder(@Validated UserIdParam userIdParam, BindingResult result){
        if (result.hasErrors()){
            return R.fail("用户id参数异常，无法查询订单");
        }
        return orderService.myOrder(userIdParam);
    }
    @GetMapping("list")
    public PageUtil<OrderVo> list(PageUtil<OrderVo> pageUtil){

        return orderService.list(pageUtil);
    }

    @GetMapping("/orderDetail")
    public R orderDetail(@Validated OrderDetailIdParam orderDetailIdParam, BindingResult result){
        if(result.hasErrors()){
            return R.fail("参数错误,查询失败");
        }
        return orderService.orderDetail(orderDetailIdParam);
    }
}
